// 流程节点类型
export type FlowNode = {
  id: string;
  type: string;
  data?: Record<string, unknown>;
  status?: 'idle' | 'running' | 'success' | 'error';
};

// 流程连线类型
export type FlowEdge = {
  source: string;
  target: string;
  data?: Record<string, unknown>;
};

// 流程数据类型
export type FlowData = {
  nodes: FlowNode[];
  edges: FlowEdge[];
};

class FlowManager {
  private flowData: FlowData;
  private status: 'idle' | 'running' | 'paused' | 'completed' | 'error';
  private context: Record<string, unknown>;

  constructor(flowData: FlowData) {
    this.flowData = flowData;
    this.status = 'idle';
    this.context = {};
  }

  // 运行流程
  run(): void {
    // TODO: 实现流程运行逻辑
    this.status = 'running';
  }

  // 暂停流程
  pause(): void {
    // TODO: 实现流程暂停逻辑
    this.status = 'paused';
  }

  // 重置流程
  reset(): void {
    // TODO: 实现流程重置逻辑
    this.status = 'idle';
    this.context = {};
    this.flowData.nodes.forEach(node => node.status = 'idle');
  }

  // 查询流程状态
  getStatus(): string {
    return this.status;
  }

  // 查询节点状态
  getNodeStatus(nodeId: string): FlowNode['status'] | undefined {
    const node = this.flowData.nodes.find(n => n.id === nodeId);
    return node?.status;
  }

  // 设置流程上下文
  setContext(key: string, value: unknown): void {
    this.context[key] = value;
  }

  // 获取流程上下文
  getContext(key: string): unknown {
    return this.context[key];
  }

  // 获取流程数据
  getFlowData(): FlowData {
    return this.flowData;
  }

  // 更新流程数据
  setFlowData(flowData: FlowData): void {
    this.flowData = flowData;
  }
}

export default FlowManager; 